﻿/*
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2009
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
*/

using System;
using DotNetNuke.Tests.UI.WatiN.SiteTests;
using MbUnit.Framework;
using WatiN.Core;
using DotNetNuke.Tests.UI.WatiN.Common;
using Gallio.Framework;
using DotNetNuke.Tests.UI.WatiN.Utilities;
using System.Configuration;
using WatiN.Core.DialogHandlers;
using DotNetNuke.Tests.UI.WatiN.Common.WatiNObjects;
using System.IO;

namespace DotNetNuke.Tests.UI.WatiN.SiteTests
{
    [TestFixture]
    public class HostMenuTests : STBase
    {


        #region Test Setup and TearDown

        [SetUp]
        public void SetUp()
        {
            SetUpTest();
        }

        [TearDown]
        public void TearDown()
        {

            TearDownTest();
        }

        #endregion

        #region Tests

        [Test]
        public void Host_Console_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\HostMenuTests\HostConsoleLoadsCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Host Console Page
                ieInstance.GoTo(SiteURL + "/Host.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnHostPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Host Page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Basic Features"), "HostTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnConsolePage.jpg");
                String[] linkTitles = new String[]
                                            {
                                                "Host Settings", "Portals", "File Manager", "Vendors",
                                                "SQL", "Schedule", "Search Admin", "Lists", "SuperUser Accounts",
                                                "Extensions", "Dashboard", "What's New",
                                                "Configuration Manager"
                                            };
                foreach (string link in linkTitles)
                {
                    watinAssert.AssertIsTrue(ieInstance.Div(Find.ByTitle(s => s.Contains(link))).Exists, "MissingLinkOnHostPage.jpg", link + " missing from page.");
                }

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "HostConsoleExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }
        }

        [Test]
        public void Host_Settings_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\HostMenuTests\HostPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Host Settings Page
                ieInstance.GoTo(SiteURL + "/Host/Host%20Settings.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnHostSettingsPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Host Settings Page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Host Settings"), "HostSettingsTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnHostSettingsPage.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "HostSiteSettingsExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }
        }

        [Test]
        public void Host_Portals_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\HostMenuTests\HostPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Host Portals Page
                ieInstance.GoTo(SiteURL + "/Host/Portals.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnPortalsPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Portals page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Portals"), "PortalsTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnPortalsPage.jpg");
                HostPortalPage portalPage = new HostPortalPage(homePage);
                watinAssert.AssertIsTrue(portalPage.PortalsTable.Exists, "PortalsTableMissing.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "HostPortalsExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }
        }

        //[Test]
        //public void Host_Module_Definitions_Page_Loads_Correctly()
        //{
        //    //Arrange
        //    string capturePath = CapturePath + @"\HostMenuTests\HostPagesLoadCorrectly\";
        //    WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
        //    if (!Directory.Exists(capturePath))
        //    {
        //        Directory.CreateDirectory(capturePath);
        //    }
        //    WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
        //    LoginPage loginPage = new LoginPage(homePage);
        //    int errorCount = 0;
        //    try
        //    {
        //        loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

        //        //Act & Assert
        //        //Visit the pages in the admin menu to assert that no errors occurred
        //        //Host Module Definitions Page
        //        ieInstance.GoTo(SiteURL + "/Host/Module%20Definitions.aspx");
        //        System.Threading.Thread.Sleep(1500);
        //        if (homePage.PageContainsErrors())
        //        {
        //            errorCount++;
        //            //Take a screen Capture
        //            ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnModuleDefinitionsPage.jpg");
        //            TestLog.WriteHighlighted("WARNING:");
        //            TestLog.WriteLine("An error occurred on the Module Definitions page, view the screen shot and exception text log for more information on the error. ");
        //        }
        //        watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Module Definitions"), "ModuleDefinitionsTitleSpanMissing.jpg");
        //        watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnModuleDefinitionsPage.jpg");
        //        ModuleDefinitionPage moduleDefinitionPage = new ModuleDefinitionPage(homePage);
        //        watinAssert.AssertIsTrue(moduleDefinitionPage.ModuleTable.Exists, "ModuleDefinitionsTableMissing.jpg");

        //        if (errorCount > 0)
        //        {
        //            //Record any recent exceptions in the log
        //            ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
        //            HostSQLPage SQLPage = new HostSQLPage(homePage);
        //            SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "HostModuleDefinitionsExceptions.txt", SiteType.Equals("Qualifier"));
        //        }
        //    }
        //    catch (Exception e)
        //    {
        //        if (!e.ToString().Contains("AssertionFailureException"))
        //        {
        //            ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
        //            Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
        //        }
        //        else
        //        {
        //            throw e;
        //        }
        //    }
        //}

        [Test]
        public void Host_File_Manager_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\HostMenuTests\HostPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Host File Manager Page
                ieInstance.GoTo(SiteURL + "/Host/File%20Manager.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnFileManagerPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the File Manager page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("File Manager"), "FileManagerTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnFileManagerPage.jpg");
                FileManagerPage fileManagerPage = new FileManagerPage(homePage);
                watinAssert.AssertIsTrue(fileManagerPage.FileManagerTable.Exists, "FileManagerTableMissing.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "HostFileManagerExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }
        }

        [Test]
        public void Host_Vendor_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\HostMenuTests\HostPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Host Vendor Page
                ieInstance.GoTo(SiteURL + "/Host/Vendors.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnVendorsPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Vendors page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Vendors"), "VendorTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnVendorPage.jpg");
                VendorsPage vendorsPage = new VendorsPage(homePage);
                watinAssert.AssertIsTrue(vendorsPage.VendorTable.Exists, "VendorTableMissing.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "HostVendorExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }
        }

        [Test]
        public void Host_SQL_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\HostMenuTests\HostPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Host SQL Page
                ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnSQLPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the SQL page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("SQL"), "SQLTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnSQLPage.jpg");
                HostSQLPage sqlPage = new HostSQLPage(homePage);
                watinAssert.AssertIsTrue(sqlPage.SQLQueryTextField.Exists, "SQLQueryFieldMissing.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    sqlPage.CheckForRecentExceptionsWriteToFile(CapturePath + "HostSQLExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }
        }

        [Test]
        public void Host_Schedule_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\HostMenuTests\HostPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Host Schedule Page
                ieInstance.GoTo(SiteURL + "/Host/Schedule.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnSchedulePage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Schedule page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Schedule"), "ScheduleTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnSchedulePage.jpg");
                SchedulePage schedulePage = new SchedulePage(homePage);
                watinAssert.AssertIsTrue(schedulePage.ScheduleEventsTable.Exists, "ScheduleTableMissing.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "HostVendorExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }
        }

        [Test]
        public void Host_Search_Admin_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\HostMenuTests\HostPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Host Search Admin Page
                ieInstance.GoTo(SiteURL + "/Host/Search%20Admin.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnSearchAdminPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Search Admin page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Search Admin"), "SearchAdminTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnSearchAdminPage.jpg");
                SearchAdminPage searchAdminPage = new SearchAdminPage(homePage);
                watinAssert.AssertIsTrue(searchAdminPage.MaximumWordLengthField.Exists, "MaximumWordLengthFieldMissing.jpg");
                watinAssert.AssertIsTrue(searchAdminPage.MinimumWordLengthField.Exists, "MinimumWordLengthFieldMissing.jpg");
                watinAssert.AssertIsTrue(searchAdminPage.IncludeCommonWordsCheckbox.Exists, "IncludeCommonWordsCheckboxMissing.jpg");
                watinAssert.AssertIsTrue(searchAdminPage.IncludeNumbersCheckbox.Exists, "IncludeNumbersCheckboxMissing.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "HostSeachAdminExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }
        }

        [Test]
        public void Host_Lists_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\HostMenuTests\HostPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Host Lists Page
                ieInstance.GoTo(SiteURL + "/Host/Lists.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnListsPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Lists page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Lists"), "ListsTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnListsPage.jpg");
                HostListPage listPage = new HostListPage(homePage);
                watinAssert.AssertIsTrue(listPage.TypesOfListsDiv.Exists, "ListTableMissing.jpg");
                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "HostListExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }
        }

        [Test]
        public void Host_Super_User_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\HostMenuTests\HostPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Host Superuser Accounts Page
                ieInstance.GoTo(SiteURL + "/Host/Superuser%20Accounts.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnSuperUserAccountsPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Superuser Accounts page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Superuser Accounts"), "SuperuserAccountsTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnSuperuserAccountsPage.jpg");
                HostUserPage hostUserPage = new HostUserPage(homePage);
                watinAssert.AssertIsTrue(hostUserPage.UserTable.Exists, "SuperUserTableMissing.jpg");
                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "HostSuperuserAccountsExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }
        }

        [Test]
        public void Host_Extensions_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\HostMenuTests\HostPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Host Extensions Page
                ieInstance.GoTo(SiteURL + "/Host/Extensions.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnExtensionsPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Extensions page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Extensions"), "ExtensionsTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnExtensionsPage.jpg");
                ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
                watinAssert.AssertIsTrue(extensionsPage.InstalledExtensionDiv.Exists, "MissingInstalledExtensionsDiv.jpg");
                watinAssert.AssertIsTrue(extensionsPage.AvailableExtensionDiv.Exists, "MissinAvailableExtensionsDiv.jpg");
                watinAssert.AssertIsTrue(extensionsPage.MoreExtensionDiv.Exists, "MissingMoreExtensionsDiv.jpg");
                watinAssert.AssertIsTrue(extensionsPage.InstallExtensionsWizardLink.Exists, "InstallExtensionLinkPresent.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "HostExtensionsExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }
        }

        [Test]
        public void Host_Dashboard_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\HostMenuTests\HostPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Host Dashboard Page
                ieInstance.GoTo(SiteURL + "/Host/Dashboard.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnDashboardPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Extensions page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Dashboard"), "DashboardTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnDashboardPage.jpg");
                watinAssert.AssertIsTrue(homePage.ContentPane.InnerHtml.Contains("Web Server Version"), "DashboardContentMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ContentPane.InnerHtml.Contains("Database Server"), "DashboardContentMissing.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "HostDashboardExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }
        }

        [Test]
        public void Host_Whats_New_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\HostMenuTests\HostPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Host Whats New Page
                ieInstance.GoTo(SiteURL + "/Host/WhatsNew.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnWhatsNewPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the What's New page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("What's New"), "WhatsNewTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnWhatsNewPage.jpg");
                watinAssert.AssertIsTrue(homePage.ContentPane.InnerHtml.Contains("Below is a summary of the major features for each release."), "WhatsNewContentMissing.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "HostWhatsNewExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }
        }

        //[Test]
        //public void Host_Marketplace_Page_Loads_Correctly()
        //{
        //    //Arrange
        //    string capturePath = CapturePath + @"\HostMenuTests\HostPagesLoadCorrectly\";
        //    WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
        //    if (!Directory.Exists(capturePath))
        //    {
        //        Directory.CreateDirectory(capturePath);
        //    }
        //    WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
        //    LoginPage loginPage = new LoginPage(homePage);
        //    int errorCount = 0;
        //    try
        //    {
        //        loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

        //        //Act & Assert
        //        //Host Marketplace Page
        //        ieInstance.GoTo(SiteURL + "/Host/Marketplace.aspx");
        //        System.Threading.Thread.Sleep(1500);
        //        if (homePage.PageContainsErrors())
        //        {
        //            errorCount++;
        //            //Take a screen Capture
        //            ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnMarketplacePage.jpg");
        //            TestLog.WriteHighlighted("WARNING:");
        //            TestLog.WriteLine("An error occurred on the Marketplace page, view the screen shot and exception text log for more information on the error. ");
        //        }
        //        watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Marketplace"), "MarketplaceTitleSpanMissing.jpg");
        //        watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnMarketplacePage.jpg");

        //        if (errorCount > 0)
        //        {
        //            //Record any recent exceptions in the log
        //            ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
        //            HostSQLPage SQLPage = new HostSQLPage(homePage);
        //            SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "HostMarketplaceExceptions.txt", SiteType.Equals("Qualifier"));
        //        }
        //    }
        //    catch (Exception e)
        //    {
        //        if (!e.ToString().Contains("AssertionFailureException"))
        //        {
        //            ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
        //            Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
        //        }
        //        else
        //        {
        //            throw e;
        //        }
        //    }
        //}


        [Test]
        public void Host_Configuration_Manager_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\HostMenuTests\HostPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            System.Threading.Thread.Sleep(1500);
            try
            {
                loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Host Marketplace Page
                ieInstance.GoTo(SiteURL + "/Host/ConfigurationManager.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnConfigurationManagerPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Configuration Manager page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Configuration Manager"), "ConfigurationManagerTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnConfigurationManagerPage.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "HostConfigurationManagerExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }
        }

        #endregion
    }
}
